<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>这是一H1标题</h1>
    <h2>这是H2标题</h2>
    <h1>这还是是一H1标题</h1>
    <script>
        function search(str,reg){
            let result = [];
            while((res=reg.exec(str))){
                result.push(res);
            }
            return result;
        }
       let cc = search(document.body.innerHTML,/<(h[1-6])>[\s\S]+?<\/\1>/gi);
       console.log(cc);
    </script>
</body>
</html>